package com.leyou.trade.utils;

import com.leyou.auth.dto.UserDetail;
import com.leyou.auth.utils.UserContext;
import org.springframework.beans.factory.annotation.Value;

/**
 * @author BaiZY on 2020/9/7.
 * @version 1.0
 */
public class CollectionNameBuilder {
    private String namePrefix;

    public CollectionNameBuilder(String namePrefix) {
        this.namePrefix = namePrefix + "_";
    }

    public String build() {
        UserDetail user = UserContext.getUser();
        if (user == null) {
            return "";
        }
        //用一个固定collection名前缀,拼接上用户的id计算出来的名字,作为collection的名字
        return namePrefix + user.getId().hashCode() % 100;
    }
}
